﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataInterpolator.Model
{
   public class DataSet
   {
      public DataSet(double xOffset, double xSpacing, IEnumerable<double> yVals)
      {
         XOffset = xOffset;
         XSpacing = xSpacing;
         _Values = new List<double>(yVals);

         MinValues = _Values.Where((v) =>
         {
            return !double.IsNaN(v);
         }).Min();
         MaxValues = _Values.Where((v) =>
         {
            return !double.IsNaN(v);
         }).Max();

         FirstValidIdx = _Values.FindIndex((v) =>
         {
            return !double.IsNaN(v);
         });

         MinX = XOffset + FirstValidIdx * xSpacing;

         LastValidIdx = _Values.FindLastIndex((v) =>
         {
            return !double.IsNaN(v);
         });

         MaxX = XOffset + LastValidIdx * xSpacing;
      }

      public double TrueOffset { get; set; }

      public double XOffset { get; private set; }

      public double XSpacing { get; private set; }

      private List<double> _Values = null;

      public List<double> Values
      {
         get { return _Values; }
      }

      public List<double> XValues
      {
         get
         {
            List<double> vals = new List<double>();

            for (int i = 0; i < _Values.Count; i++)
            {
               vals.Add(i);
            }

            return vals;
         }
      }

      public double MinValues { get; private set; }

      public double MaxValues { get; private set; }

      public double MinX { get; private set; }

      public double MaxX { get; private set; }

      public int FirstValidIdx
      {
         get; private set;
      }
      public int LastValidIdx
      {
         get; private set;
      }

      public int ValidIdxCount
      {
         get
         {
            return LastValidIdx - FirstValidIdx + 1;
         }
      }
   }
}
